// myorder.js

const app=getApp()

Page({

  /**
   * 页面的初始数据
   */
  data: {
    // nav
    nav: { item01: "全部",/* item02: "未支付",*/ item02: "已支付", item03: "已消费"},
    curIndex: "x0",
    left: "0",
    Info:[],
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    var that=this;
    wx.request({
      url: 'https://soya.91soya.com/api/showorder/' + app.globalData.openId,
      method: "get",
      success: function (res) {
        var resp = res.data;
        
        var a = [];
        if (resp.length != 0) {
          for (var i = 0; i < resp.length; i++) {
            a[i] = { id: resp[i].id, pid: resp[i].pid, tImg: " https://soya.91soya.com/uploads/" + resp[i].type_img, tName: resp[i].name, pImg: " https://soya.91soya.com/uploads/" + resp[i].img, pName: resp[i].pro_name, storeImg: "/imgs/storeAc.png", price: resp[i].price, yPrice: resp[i].y_price, }
          }
          var inf0 = "Info[0].pInfo";
          that.setData({
            [inf0]: a
          })
        }
        for (var i = 0; i < resp.length; i++) {
          if (resp[i].status == 1) {
            console.log("1")
            var b = [];
            b.push({ id: resp[i].id, pid: resp[i].pid, tImg: " https://soya.91soya.com/uploads/" + resp[i].type_img, tName: resp[i].name, pImg: " https://soya.91soya.com/uploads/" + resp[i].img, pName: resp[i].pro_name, storeImg: "/imgs/storeAc.png", price: resp[i].price, yPrice: resp[i].y_price, })
            var inf1 = "Info[1].pInfo";
            that.setData({
              [inf1]: b
            })
          } else if (resp[i].status == 2) {
            console.log("2")
            var c = [];
            c.push({ id: resp[i].id, pid: resp[i].pid, tImg: " https://soya.91soya.com/uploads/" + resp[i].type_img, tName: resp[i].name, pImg: " https://soya.91soya.com/uploads/" + resp[i].img, pName: resp[i].pro_name, storeImg: "/imgs/storeAc.png", price: resp[i].price, yPrice: resp[i].y_price, }) 
            var inf2 = "Info[2].pInfo";
            that.setData({
              [inf2]: c
            })
          }
        }
      }
    })
  },
  Nav:app.Nav(this),
})
